<template>
  <div>

    <avue-form :key="actFormKey"
               ref="avueForm"
               :option="actFormOption"
               v-model="actFormModel"
               @submit="submitForm"></avue-form>

  </div>

</template>

<script>
import startActFormApi from "@/api/start/activiti/core/startActFormApi";
import startActFormTools from "./startActFormTools";

export default {
  name: "startActMainForm",
  props: {
    formBtn: {
      type: Boolean,
      default: true,
    },
    detail: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      actFormKey: Math.random(),
      actFormModel: {},
      actFormOption: {menuBtn: false},

    }
  },
  created() {

  },
  methods: {
    init(actFormConf, formModel) {
      this.actFormModel = formModel || {}
      this.initFormOption(actFormConf);
    },
    initFormOption(actFormConf) {
      startActFormApi.getActFormOption(actFormConf.id).then(this.analysisForm)
    },
    analysisForm(res) {
      let data = res.data.data;
      data.menuBtn = false;
      data.detail = this.detail
      startActFormTools.autoActMainForm(data)
      this.actFormOption = data;
    },

    submit() {
      this.$refs.avueForm.submit();
    },
    resetForm() {
      this.$refs.avueForm.resetForm();
    },
    submitForm(data, done) {
      data.businessKey = "";
      let formData = {};
      for (const key in data) {
        if (key.startsWith("$")) {
          continue
        }
        formData[key] = data[key];
      }
      this.$emit("submit", formData, done)
    },

  }
}
</script>

<style scoped>

</style>
